package com.t3h.tamle.settingdemo;

import java.util.ArrayList;

import android.R.anim;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

public class SettingDemoActivity extends Activity {
	private ListView listView;
	private TextView language;
	private ArrayList<String> arrayList;

	public static final String LANGUAGE = "language";
	public static final String OPTIONS = "option";
	public static final int LANGUAGE_REQUEST = 1;
	public static final int OPTIONS_REQUEST = 2;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		Listener listener = new Listener();
		arrayList = new ArrayList<String>();
		listView = (ListView) findViewById(R.id.list_option);
		listView.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, arrayList));
		language = (TextView) findViewById(R.id.selected_language);
		findViewById(R.id.language).setOnClickListener(listener);
		findViewById(R.id.option).setOnClickListener(listener);

	}

	class Listener implements OnClickListener {

		public void onClick(View v) {
			// TODO Auto-generated method stub
			switch (v.getId()) {
			case R.id.language:
				Intent intent = new Intent(SettingDemoActivity.this,
						LanguageActivity.class);
				startActivityForResult(intent, LANGUAGE_REQUEST);

				break;
			case R.id.option:
				intent = new Intent(SettingDemoActivity.this,
						OptionActivity.class);
				startActivityForResult(intent, OPTIONS_REQUEST);
				break;

			default:
				break;
			}

		}

	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		if (resultCode == RESULT_OK) {
			switch (requestCode) {
			case LANGUAGE_REQUEST:
				String str = data.getStringExtra(LANGUAGE);
				Log.i("Tamle", "language: " + str);
				language.setText(str);
				break;
			case OPTIONS_REQUEST:
				arrayList = data.getStringArrayListExtra(OPTIONS);
				for (String seleccted : arrayList) {
					Log.i("Tamle", "result: " + seleccted);
				}
				listView.setAdapter(new ArrayAdapter<String>(this,
						android.R.layout.simple_list_item_1, arrayList));
				break;

			default:
				break;
			}

		}
	}
}